package client.network;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Observable;

public class DrawMailBox extends Observable {
	ArrayList<ArrayList<Point>> incomingPoints;
	ArrayList<ArrayList<Point>> outgoingPoints;

	public DrawMailBox() {
		incomingPoints = new ArrayList<ArrayList<Point>>();
		outgoingPoints = new ArrayList<ArrayList<Point>>();
	}

	public synchronized void addIncomingPoints(ArrayList<Point> points) {
		incomingPoints.add(points);
		notifyAll();
	}

	public synchronized void drawIncomingPoints() {
		while (incomingPoints.isEmpty()) {
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		ArrayList<Point> temp = incomingPoints.remove(0);
		setChanged();
		notifyObservers(temp);
		notifyAll();
	}

	public synchronized void addOutgoingPoints(ArrayList<Point> points) {
		outgoingPoints.add(points);
		notifyAll();
	}

	public synchronized ArrayList<Point> getOutgoingPoints() {
		while (outgoingPoints.isEmpty()) {
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		ArrayList<Point> temp = outgoingPoints.remove(0);
		notifyAll();
		return temp;
	}

}
